package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.cart.client.CartFeignClient;
import com.atguigu.gmall.common.util.AuthContextHolder;
import com.atguigu.gmall.model.cart.CartInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: 李旭
 * @Time: 14:24
 * @Description:
 */
@Controller
public class CartInfoController {


    public static final String REDIRECTURL = "http://cart.gmall.com/toCart.html";
    @Autowired
    private CartFeignClient cartFeignClient;
    //加入购物车
    @GetMapping("/addCart.html")
    public String cart(Long skuId, Integer skuNum, RedirectAttributes redirectAttributes){
        cartFeignClient.addToCart(skuId, skuNum);//业务参数  记得传递用户ID
        redirectAttributes.addAttribute("pid",skuId);
        redirectAttributes.addAttribute("pc",skuNum);
        return "redirect:" + REDIRECTURL;//Springmvc
    }
    //重定向到
    @GetMapping("/toCart.html")
    public String toCart(Long pid, Integer pc, Model model){
        CartInfo cartInfo = cartFeignClient.toCart(pid);
        cartInfo.setSkuNum(pc);
        model.addAttribute("cartInfo",cartInfo);
        return "cart/addCart";
    }
    //去购物车结算
    @GetMapping("/cart.html")
    public String cart(){

        return "cart/index";
    }
}
